-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
buffer: add Buffer.fromHex() and Buffer.fromBase64()
#61157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
buffer: add Buffer.fromHex() and Buffer.fromBase64()
#61157
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #61157 +/- ##
==========================================
+ Coverage 88.52% 88.55% +0.02%
==========================================
Files 703 704 +1
Lines 208589 208810 +221
Branches 40226 40281 +55
==========================================
+ Hits 184650 184908 +258
+ Misses 15954 15926 -28
+ Partials 7985 7976 -9
🚀 New features to boost your workflow:
|
|
Remember to update the docs |
avivkeller
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than this is missing a doc entry, LGTM
|
Agreed, added to the docs. |
avivkeller
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs + impl lgtm
lib/buffer.js
Outdated
| * @returns {Buffer} | ||
| */ | ||
| Buffer.fromHex = function fromHex(str) { | ||
| // TODO(LiviaMedeiros): replace with primordial once `--js-base-64` is not optional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we define those only if --no-js-base-64 as it is the case today?
$ node --no-js-base-64 -p 'Buffer.fromHex'
undefined
$ node -p 'Buffer.fromHex'
[Function: fromHex]|
I don't think lazy loading makes sense here, I don't see what's the upside. Why not put it under an if statement instead? $ ./node -p '"fromHex" in Buffer'
true
$ ./node --no-js-base-64 -p '"fromHex" in Buffer'
false |
|
@aduh95 IIUC 'fromHex' in Uint8Array
Uint8Array.fromHex !== undefined
typeof Uint8Array.fromHex !== 'undefined'
const { Uint8Array: { fromHex } } = primordials
const { globalThis: { Uint8Array: { fromHex } } } = primordials
const { Uint8Array: { fromHex } } = globalThisgives anything meaningful. |
These methods are already present on
Uint8Array, so without defining them onBufferthey return instances ofUint8Array. This introduces wrapper to return instances ofBufferinstead.Fixes: #61146